// pages/shoppingCar/shoppingCar.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
address:false,
isProduct:false,
addressInfo:{},
Products:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
this.getAddress()
  },
  onShow(){
    this.getShopCar()
  },
  getAddress(){
let addressInfo = wx.getStorageSync('addressInfo') || ''
if(addressInfo){
  this.setData({
    addressInfo,
    address:true
  })
}else{
  this.setData({
    address:false
  })
}
  },
  getShopCar(){
let shoppingCar=wx.getStorageSync('shoppingCar') || []
// shoppingCar.push({'cat_id':num})
// wx.setStorageSync('shoppingCar', shoppingCar)

if(shoppingCar.length != 0){
this.setData({
  isProduct:true,
  Products:shoppingCar
})
}
  },
  addAddress(e){
    wx.chooseAddress({
      success: (result) => {
        let obj={
          name:result.userName,
          phone:result.telNumber,
          detail:result.provinceName+result.cityName+result.countyName+result.detailInfo
        }
        // console.log("obj",obj)
wx.setStorageSync('addressInfo',obj)
        this.setData({
          addressInfo:obj,
          address:true
        })
      },
    })
  },
  goCate(){
    wx.switchTab({
      url: '../catetory/catetory',
    })
  }
})